import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsBoolean, IsEnum, IsNotEmpty, IsNumber, IsOptional, MaxLength } from 'class-validator';

export class ResourceDto {
  @ApiProperty({ required: true, description: '资源名称' })
  @IsNotEmpty({ message: '资源名称不能为空' })
  @MaxLength(30, { message: '资源名称的长度不能超过30' })
  name: string;

  @ApiProperty({ required: true, description: '类型' })
  @IsEnum(
    { 菜单: 'menu', 接口: 'api', 按钮: 'btn' },
    { message: '类型必须是(menu表示菜单,api表示接口，btn表示按钮)' },
  )
  type: string;

  @ApiPropertyOptional({ required: false, description: '菜单是否显示' })
  @IsBoolean({ message: '菜单是否显示只能是布尔值' })
  @IsOptional()
  isShow?: boolean;

  @ApiPropertyOptional({ required: false, description: '菜单图标' })
  @IsOptional()
  icon?: string;

  @ApiPropertyOptional({ required: false, description: '菜单code' })
  @IsOptional()
  code: string;

  @ApiPropertyOptional({ required: false, description: '排序' })
  @IsNumber()
  @IsOptional()
  sort?: number;

  @ApiProperty({ required: true, description: '组件路径' })
  @IsNotEmpty({ message: '组件路径不能为空' })
  componentPath: string;

  @ApiProperty({ required: true, description: '组件名称' })
  @IsNotEmpty({ message: '组件名称不能为空' })
  componentName: string;

  @ApiPropertyOptional({ required: false, description: '是否需要缓存' })
  @IsOptional()
  cache?: boolean;

  @ApiPropertyOptional({ required: false, description: '上一级ID' })
  @IsOptional()
  parentId?: string;
}
